package com.itheima;

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.FileOutputStream;

/**
 * @author 黑马程序员
 * @Company http://www.ithiema.com
 * @Version 1.0
 */
public class POIWrite {
    public static void main(String[] args) throws Exception{
        //创建excel表格【工作薄】
        XSSFWorkbook workbook = new XSSFWorkbook();
//创建工作表
        XSSFSheet sheet = workbook.createSheet("abc");
//创建行对象
        XSSFRow row = sheet.createRow(0);
//创建单元格
        XSSFCell cell1 = row.createCell(0);
        cell1.setCellValue("username");
        XSSFCell cell2 = row.createCell(1);
        cell2.setCellValue("age");

//创建行对象
        XSSFRow row2 = sheet.createRow(1);
//创建单元格
        XSSFCell cell3 = row2.createCell(0);
        cell3.setCellValue("张三");
        XSSFCell cell4 = row2.createCell(1);
        cell4.setCellValue("23");



        FileOutputStream fileOutputStream = new FileOutputStream("C:\\Users\\sun\\Desktop\\test2.xlsx");
        workbook.write(fileOutputStream);


        fileOutputStream.flush();
        workbook.close();
        fileOutputStream.close();


    }
}
